package com.kds.smarthome.config;

import com.kds.smarthome.annotation.BuildingCode;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class BuildingCodeArgumentResolver implements HandlerMethodArgumentResolver {

    private static final String BUILDING_CODE_HEADER = "x-building-code";

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation(BuildingCode.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                                NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
        return webRequest.getHeader(BUILDING_CODE_HEADER);
    }
} 